package cloud.zhixinglu.www.spring.boot.utils.date;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * FormatDateUtil
 * </p>
 *
 * @author weixin
 * @date 2023/4/17 10:45
 */
public class FormatDateUtil {

    private static final ThreadLocal<DateFormat> DATE_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

    private FormatDateUtil() {
        // private constructor to prevent instantiation
    }

    /**
     * 格式化时间
     * @param date Date 日期
     * @return String
     */
    public static String format(Date date) {
        return DATE_FORMAT.get().format(date);
    }

    /**
     * 清除
     */
    public static void clearThreadLocal() {
        DATE_FORMAT.remove();
    }

}
